package jjwt.study.Config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

/**
 * 描述:JWT配置类
 * 注意access、token转换方法里面的密钥
 * @author Ychiha
 * @version 1.0
 * @date 15/1/2022 上午12:02
 */
@Configuration
public class JwtTokenStoreConfig {

    @Bean
    public TokenStore jwtTokenStore() {
        return new JwtTokenStore(jwtAccessTokenConverter());
    }

    @Bean
    public JwtAccessTokenConverter jwtAccessTokenConverter() {
        JwtAccessTokenConverter accessTokenConverter = new JwtAccessTokenConverter();
        //  配置 JWT 使用的密钥
        accessTokenConverter.setSigningKey("test_key");
        return  accessTokenConverter;
    }

    /**
     * jwt内容增强器 (JwtTokenEnhancer类不用添加@Config 否则报错)
     * @return
     */
    @Bean
    public JwtTokenEnhancer jwtTokenEnhancer() {
        return new JwtTokenEnhancer();
    }

}
